<HTML>
<HEAD>
<!-- Created by texi2html 1.56k from /home/jaffer/scheme/r5rs.txi on 28 March 2001 -->

<TITLE>Revised(5) Scheme - 1. Overview of Scheme</TITLE>
</HEAD>
<BODY>
Go to the <A HREF="r5rs_1.html">first</A>, <A HREF="r5rs_2.html">previous</A>, <A HREF="r5rs_4.html">next</A>, <A HREF="r5rs_14.html">last</A> section, <A HREF="r5rs_toc.html">table of contents</A>.
<P><HR><P>


<H1><A NAME="SEC5" HREF="r5rs_toc.html#TOC5">1. Overview of Scheme</A></H1>

<P>
<A NAME="IDX5"></A>




<H2><A NAME="SEC6" HREF="r5rs_toc.html#TOC6">1.1 Semantics</A></H2>

<P>
<A NAME="IDX6"></A>


<P>
This section gives an overview of Scheme's semantics.  A
detailed informal semantics is the subject of
chapters section <A HREF="r5rs_5.html#SEC18">3. Basic concepts</A> through section <A HREF="r5rs_8.html#SEC48">6. Standard procedures</A>.  For reference
purposes, section <A HREF="r5rs_9.html#SEC79">7.2 Formal semantics</A> provides a formal
semantics of Scheme.


<P>
Following Algol, Scheme is a statically scoped programming
language.  Each use of a variable is associated with a lexically
apparent binding of that variable.


<P>
Scheme has latent as opposed to manifest types.  Types
are associated with values (also called objects) rather than
<A NAME="IDX7"></A>
with variables.  (Some authors refer to languages with latent types as
weakly typed or dynamically typed languages.)  Other languages with
latent types are APL, Snobol, and other dialects of Lisp.  Languages
with manifest types (sometimes referred to as strongly typed or
statically typed languages) include Algol 60, Pascal, and C.


<P>
All objects created in the course of a Scheme computation, including
procedures and continuations, have unlimited extent.
No Scheme object is ever destroyed.  The reason that
implementations of Scheme do not (usually!) run out of storage is that
they are permitted to reclaim the storage occupied by an object if
they can prove that the object cannot possibly matter to any future
computation.  Other languages in which most objects have unlimited
extent include APL and other Lisp dialects.


<P>
Implementations of Scheme are required to be properly tail-recursive.
This allows the execution of an iterative computation in constant space,
even if the iterative computation is described by a syntactically
recursive procedure.  Thus with a properly tail-recursive implementation,
iteration can be expressed using the ordinary procedure-call
mechanics, so that special iteration constructs are useful only as
syntactic sugar.  See section <A HREF="r5rs_5.html#SEC23">3.5 Proper tail recursion</A>.


<P>
Scheme procedures are objects in their own right.  Procedures can be
created dynamically, stored in data structures, returned as results of
procedures, and so on.  Other languages with these properties include
Common Lisp and ML. 


<P>
One distinguishing feature of Scheme is that continuations, which
in most other languages only operate behind the scenes, also have
"first-class" status.  Continuations are useful for implementing a
wide variety of advanced control constructs, including non-local exits,
backtracking, and coroutines.  See section <A HREF="r5rs_8.html#SEC64">6.4 Control features</A>.


<P>
Arguments to Scheme procedures are always passed by value, which
means that the actual argument expressions are evaluated before the
procedure gains control, whether the procedure needs the result of the
evaluation or not.  ML, C, and APL are three other languages that always
pass arguments by value.
This is distinct from the lazy-evaluation semantics of Haskell,
or the call-by-name semantics of Algol 60, where an argument
expression is not evaluated unless its value is needed by the
procedure.


<P>
Scheme's model of arithmetic is designed to remain as independent as
possible of the particular ways in which numbers are represented within a
computer. In Scheme, every integer is a rational number, every rational is a
real, and every real is a complex number.  Thus the distinction between integer
and real arithmetic, so important to many programming languages, does not
appear in Scheme.  In its place is a distinction between exact arithmetic,
which corresponds to the mathematical ideal, and inexact arithmetic on
approximations.  As in Common Lisp, exact arithmetic is not limited to
integers.




<H2><A NAME="SEC7" HREF="r5rs_toc.html#TOC7">1.2 Syntax</A></H2>

<P>
<A NAME="IDX8"></A>


<P>
Scheme, like most dialects of Lisp, employs a fully parenthesized prefix
notation for programs and (other) data; the grammar of Scheme generates a
sublanguage of the language used for data.  An important
consequence of this simple, uniform representation is the susceptibility of
Scheme programs and data to uniform treatment by other Scheme programs.
For example, the <SAMP>`eval'</SAMP> procedure evaluates a Scheme program expressed
as data.


<P>
The <SAMP>`read'</SAMP> procedure performs syntactic as well as lexical decomposition of
the data it reads.  The <SAMP>`read'</SAMP> procedure parses its input as data
(section see section <A HREF="r5rs_9.html#SEC74">7.1.2 External representations</A>), not as program.


<P>
The formal syntax of Scheme is described in section <A HREF="r5rs_9.html#SEC72">7.1 Formal syntax</A>.




<H2><A NAME="SEC8" HREF="r5rs_toc.html#TOC8">1.3 Notation and terminology</A></H2>

<P>
<A NAME="IDX9"></A>




<H3><A NAME="SEC9" HREF="r5rs_toc.html#TOC9">1.3.1 Primitive; library; and optional features</A></H3>

<P>
<A NAME="IDX10"></A>


<P>
It is required that every implementation of Scheme support all
features that are not marked as being <EM>optional</EM>.  Implementations are
<A NAME="IDX11"></A>
free to omit optional features of Scheme or to add extensions,
provided the extensions are not in conflict with the language reported
here.  In particular, implementations must support portable code by
providing a syntactic mode that preempts no lexical conventions of this
report.


<P>
To aid in understanding and implementing Scheme, some features are marked
as <EM>library</EM>. These can be easily implemented in terms of the other,
<A NAME="IDX12"></A>
primitive, features.  They are redundant in the strict sense of
the word, but they capture common patterns of usage, and are therefore
provided as convenient abbreviations.




<H3><A NAME="SEC10" HREF="r5rs_toc.html#TOC10">1.3.2 Error situations and unspecified behavior</A></H3>

<P>
<A NAME="IDX13"></A>


<P>
<A NAME="IDX14"></A>
When speaking of an error situation, this report uses the phrase "an
error is signalled" to indicate that implementations must detect and
report the error.  If such wording does not appear in the discussion of
an error, then implementations are not required to detect or report the
error, though they are encouraged to do so.  An error situation that
implementations are not required to detect is usually referred to simply
as "an error."


<P>
For example, it is an error for a procedure to be passed an argument that
the procedure is not explicitly specified to handle, even though such
domain errors are seldom mentioned in this report.  Implementations may
extend a procedure's domain of definition to include such arguments.


<P>
This report uses the phrase "may report a violation of an
implementation restriction" to indicate circumstances under which an
implementation is permitted to report that it is unable to continue
execution of a correct program because of some restriction imposed by the
implementation.  Implementation restrictions are of course discouraged,
but implementations are encouraged to report violations of implementation
restrictions.
<A NAME="IDX15"></A>


<P>
For example, an implementation may report a violation of an
implementation restriction if it does not have enough storage to run a
program.


<P>
If the value of an expression is said to be "unspecified," then
the expression must evaluate to some object without signalling an error,
but the value depends on the implementation; this report explicitly does
not say what value should be returned. 
<A NAME="IDX16"></A>




<H3><A NAME="SEC11" HREF="r5rs_toc.html#TOC11">1.3.3 Entry format</A></H3>

<P>
<A NAME="IDX17"></A>


<P>
Chapters section <A HREF="r5rs_6.html#SEC24">4. Expressions</A> and section <A HREF="r5rs_8.html#SEC48">6. Standard procedures</A> are organized
into entries.  Each entry describes one language feature or a group of
related features, where a feature is either a syntactic construct or a
built-in procedure.  An entry begins with one or more header lines of the form


<P>
<A NAME="IDX18"></A>
<DL>
<DT><U><VAR>category</VAR>:</U> <B><VAR>template</VAR></B>
<DD>


</DL>

<P>
for required, primitive features, or


<P>
<A NAME="IDX19"></A>
<DL>
<DT><U><VAR>qualifier</VAR> <VAR>category</VAR>:</U> <B><VAR>template</VAR></B>
<DD>


</DL>

<P>
where <VAR>qualifier</VAR> is either "library" or "optional" as defined
 in section <A HREF="r5rs_3.html#SEC9">1.3.1 Primitive; library; and optional features</A>.


<P>
If <VAR>category</VAR> is "syntax", the entry describes an expression
type, and the template gives the syntax of the expression type.
Components of expressions are designated by syntactic variables, which
are written using angle brackets, for example, &#60;expression&#62;,
&#60;variable&#62;.  Syntactic variables should be understood to denote segments of
program text; for example, &#60;expression&#62; stands for any string of
characters which is a syntactically valid expression.  The notation



<PRE>
 &#60;thing1&#62; ...
</PRE>

<P>
indicates zero or more occurrences of a &#60;thing&#62;, and



<PRE>
 &#60;thing1&#62; &#60;thing2&#62; ...
</PRE>

<P>
indicates one or more occurrences of a &#60;thing&#62;.


<P>
If <VAR>category</VAR> is "procedure", then the entry describes a procedure, and
the header line gives a template for a call to the procedure.  Argument
names in the template are <VAR>italicized</VAR>.  Thus the header line


<P>
<A NAME="IDX20"></A>
<DL>
<DT><U>procedure:</U> <B>(vector-ref</B> <I><VAR>vector</VAR> <VAR>k</VAR>)</I>
<DD>


</DL>

<P>
indicates that the built-in procedure <TT>vector-ref</TT> takes
two arguments, a vector <VAR>vector</VAR> and an exact non-negative integer
<VAR>k</VAR> (see below).  The header lines


<P>


<P>
<A NAME="IDX21"></A>
<A NAME="IDX22"></A>
<DL>
<DT><U>procedure:</U> <B>(make-vector</B> <I><VAR>k</VAR>)</I>
<DD>


<P>
<DT><U>procedure:</U> <B>(make-vector</B> <I><VAR>k</VAR> <VAR>fill</VAR>)</I>
<DD>


</DL>

<P>
indicate that the <TT>make-vector</TT> procedure must be defined to take
either one or two arguments.


<P>
It is an error for an operation to be presented with an argument that it
is not specified to handle.  For succinctness, we follow the convention
that if an argument name is also the name of a type listed in
section <A HREF="r5rs_5.html#SEC20">3.2 Disjointness of types</A>, then that argument must be of the named type.
For example, the header line for <TT>vector-ref</TT> given above dictates that the
first argument to <TT>vector-ref</TT> must be a vector.  The following naming
conventions also imply type restrictions:


<P>

<BLOCKQUOTE>
<DL COMPACT>

<DT><VAR>obj</VAR>
<DD>
any object
<DT><VAR>list</VAR>, <VAR>list1</VAR>, ... <VAR>listj</VAR>, ...
<DD>
list (see section see section <A HREF="r5rs_8.html#SEC59">6.3.2 Pairs and lists</A>)
<DT><VAR>z</VAR>, <VAR>z1</VAR>, ... <VAR>zj</VAR>, ...
<DD>
complex number
<DT><VAR>x</VAR>, <VAR>x1</VAR>, ... <VAR>xj</VAR>, ...
<DD>
real number
<DT><VAR>y</VAR>, <VAR>y1</VAR>, ... <VAR>yj</VAR>, ...
<DD>
real number
<DT><VAR>q</VAR>, <VAR>q1</VAR>, ... <VAR>qj</VAR>, ...
<DD>
rational number
<DT><VAR>n</VAR>, <VAR>n1</VAR>, ... <VAR>nj</VAR>, ...
<DD>
integer
<DT><VAR>k</VAR>, <VAR>k1</VAR>, ... <VAR>kj</VAR>, ...
<DD>
exact non-negative integer
<DT>
<DD>
</DL>
</BLOCKQUOTE>



<H3><A NAME="SEC12" HREF="r5rs_toc.html#TOC12">1.3.4 Evaluation examples</A></H3>

<P>
<A NAME="IDX23"></A>


<P>
The symbol "=>" used in program examples should be read
"evaluates to."  For example,



<PRE>

(* 5 8)                                ==&#62;  40

</PRE>

<P>
means that the expression <TT>(* 5 8)</TT> evaluates to the object <TT>40</TT>.
Or, more precisely:  the expression given by the sequence of characters
"<TT>(* 5 8)</TT>" evaluates, in the initial environment, to an object
that may be represented externally by the sequence of characters "<TT>40</TT>".  See section <A HREF="r5rs_5.html#SEC21">3.3 External representations</A> for a discussion of external
representations of objects.




<H3><A NAME="SEC13" HREF="r5rs_toc.html#TOC13">1.3.5 Naming conventions</A></H3>

<P>
<A NAME="IDX24"></A>


<P>
By convention, the names of procedures that always return a boolean
value usually end
in "<CODE>?</CODE>".  Such procedures are called predicates.
<A NAME="IDX25"></A>


<P>
By convention, the names of procedures that store values into previously
allocated locations (see section see section <A HREF="r5rs_5.html#SEC22">3.4 Storage model</A>) usually end in
"<CODE>!</CODE>".
<A NAME="IDX26"></A>
Such procedures are called mutation procedures.
By convention, the value returned by a mutation procedure is unspecified.


<P>
By convention, "<CODE>-&#62;</CODE>" appears within the names of procedures that
<A NAME="IDX27"></A>
take an object of one type and return an analogous object of another type.
For example, <SAMP>`list-&#62;vector'</SAMP> takes a list and returns a vector whose
elements are the same as those of the list.


<P>
        


<P>
  


<P><HR><P>
Go to the <A HREF="r5rs_1.html">first</A>, <A HREF="r5rs_2.html">previous</A>, <A HREF="r5rs_4.html">next</A>, <A HREF="r5rs_14.html">last</A> section, <A HREF="r5rs_toc.html">table of contents</A>.
</BODY>
</HTML>
